home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1 Issue 2 / PDCD-1 - Issue 02.iso / _comms / comms / _uuexplode / !uuexplode_l_UUEXPLO < prev    next >
Encoding:
Text File  |  1993-08-02  |  17.3 KB  |  657 lines

  1.      1  
  2.     63  
  3.     63  
  4.     63  
  5.     63  
  6.     63  
  7.     63  
  8.     63  
  9.     63  
  10.     63  
  11.     63  
  12.     63  
  13.     63  
  14.     63  
  15.     63  
  16.     63  
  17.     63  
  18.     63  
  19.     63  
  20.     63  
  21.     63  
  22.     63  
  23.     63  
  24.     63  
  25.     63  
  26.     63  
  27.     63  
  28.     63  
  29.     63  
  30.     63  
  31.     63  
  32.     63  
  33.     63  
  34.     63  
  35.     63  
  36.     63  
  37.     63  
  38.     63  
  39.     63  
  40.     63  
  41.     63  
  42.     63  
  43.     63  
  44.     63  
  45.     63  
  46.     63  
  47.     63  
  48.     63  
  49.     63  
  50.     63  
  51.     63  
  52.     63  
  53.     63  
  54.     63  
  55.     63  
  56.     63  
  57.     63  
  58.     63  
  59.     63  
  60.     63  
  61.     63  
  62.     63  
  63.     63  
  64.     64  
  65.     68  
  66.     69  
  67.     70  
  68.     71  
  69.     72  
  70.     73  
  71.     74  
  72.     75  
  73.     76  
  74.     77  
  75.     78  
  76.     81  
  77.     81  
  78.     81  
  79.     82  static char input_buf[256],
  80.     83              b[256] = " ";   
  81.     85  
  82.     85  static char out_buf[256], dest[256], dummy[256];
  83.     86  
  84.     87  static char *ibuf = input_buf, *bp = b, *obuf = out_buf, *tmp, *p;
  85.     88  static char *filebuf1 = 0 ,
  86.     89              *filebuf2 = 0 ;   
  87.     90  static int line, len, mlen, dlen, count,
  88.     91         mode, newdata, hasdata, bquote, bquoteline, end,
  89.     92         verbose=1, secure=0, ambiguous, truncation=0,
  90.     93         t, i, x, y, z;
  91.     94  static int siz = 256;
  92.     95  static FILE *ofp;
  93.     96  
  94.     97  
  95.     98  int ExplodeFile();
  96.     99  int ExplodeLine();
  97.    100  int ExplodeLineCheck();
  98.    101  
  99.    102  
  100.    103  
  101.    107  
  102.    107  
  103.    107  
  104.    107  int uuchk(char *s)
  105.    108  {
  106.    109    int i, top;
  107.    110   
  108.    111    top = len-(mlen-62); 
  109.    112    for(i=1; i<top; i++)           
  110.    113      if (*s++ >= 'a') return 0;   
  111.    114    return 1;
  112.    115  }
  113.    116  
  114.    117  
  115.    118  main(int argc, char *argv[])
  116.    119  {
  117.    120    FILE *ifp;
  118.    121    char *pname;
  119.    122  
  120.    123    pname = argv[0];
  121.    124    while (argc > 1 && *argv[1] == '-')   
  122.    125      {
  123.    126        if (*(argv[1]+1) == 'q')          
  124.    127          {
  125.    128            verbose = 0;
  126.    129            argc--;
  127.    130            argv++;
  128.    131          }
  129.    132        else if (*(argv[1]+1) == 'h')   
  130.    133          {
  131.    134            printf("Usage: %s [-q | -h | -s] [file1 [file2...]]\n", argv[0]);
  132.    135            printf("-q  quiet\n-h  usage\n-s  secure, check all data lines\n");
  133.    136            printf("When you get warnings check the input.\n");
  134.    137            return;
  135.    138          }
  136.    139        else if (*(argv[1]+1) == 's')   
  137.    140          {
  138.    141            secure = 1;
  139.    142            argc--;
  140.    143            argv++;
  141.    144         }
  142.    145      }
  143.    146    ;
  144.    147    if (argc < 2)
  145.    148      {
  146.    149        line = 0;   
  147.    150        ExplodeFile((&__iob[0]), "stdin");      
  148.    151      }
  149.    152    else 
  150.    153      {
  151.    154        if ((filebuf1 = malloc(262144)) == 0 
  152.    155            || (filebuf2 = malloc(262144)) == 0 )
  153.    156          fprintf((&__iob[2]), "%s: buffer allocation failed.\n", pname);
  154.    157        
  155.    158        for (; --argc && ++argv; )
  156.    159          {
  157.    160            if ((ifp = fopen(*argv,"r")) == 0 )
  158.    161              {
  159.    162                perror(*argv);
  160.    163                continue;
  161.    164              }
  162.    165            if (filebuf1 != 0 )
  163.    166              setvbuf(ifp, filebuf1,0x100 , 262144);
  164.    167            line = 0;                 
  165.    168            ExplodeFile(ifp, *argv);  
  166.    169            
  167.    170            
  168.    171            
  169.    172            
  170.    173            fclose(ifp);
  171.    174          }
  172.    175      }
  173.    176   return;   
  174.    177  }
  175.    178  
  176.    179  
  177.    180  
  178.    181  
  179.    182  int ExplodeFile(FILE *ifp, char *fname)
  180.    183  {
  181.    184    hasdata = mlen = 0;
  182.    185  
  183.    186    
  184.    187    while (fgets(ibuf, siz, ifp) != 0 )
  185.    188      {
  186.    189        while (1)
  187.    190          {
  188.    191            line++;
  189.    192            if (! strncmp(ibuf, "begin ", 6)
  190.    193                && (__ctype[ibuf[6]] & 32 )
  191.    194                && (__ctype[ibuf[7]] & 32 )
  192.    195                && (__ctype[ibuf[8]] & 32 ))
  193.    196              {
  194.    197                break;   
  195.    198              }
  196.    199            if (fgets(ibuf, siz, ifp) == 0 )   
  197.    200              {
  198.    201                if (! hasdata) printf("%s: no begin line\n", fname);
  199.    202                return;
  200. +++ Warning: non-value return in non-void function
  201.    203              }
  202.    204          }
  203.    205  
  204.    206            
  205.    207        if ((sscanf(ibuf, "begin %o%[ ]%s", &mode, dummy, dest)) != 3)
  206.    208          {
  207.    209            len = strlen(ibuf);
  208.    210            ibuf[len-1] = 0;      
  209.    211            printf("%s: %s: Invalid mode or filename\n", fname, ibuf);
  210.    212            continue;     
  211.    213          }
  212.    214        hasdata = 1;      
  213.    215        if (verbose) 
  214.    216          {
  215.    217            printf("Extracting <%s>\t", dest);
  216.    218            
  217.    219            fflush((&__iob[1]));
  218.    220          }
  219.    221  
  220.    222        
  221.    223        if ((ofp = fopen(strcat(getenv("Out$path"),dest), "w")) == 0 )
  222. +++ Warning: <function argument>: implicit cast of non-0 int to pointer
  223.    224          {
  224.    225            perror(dest);
  225.    226            continue;
  226.    227          }
  227.    228  
  228.    230  
  229.    230        if (filebuf2 != 0 )
  230.    231          setvbuf(ofp, filebuf2,0x100 , 262144);
  231.    232        
  232.    233        
  233.    241  
  234.    241  
  235.    241  
  236.    241  
  237.    241  
  238.    241  
  239.    241  
  240.    241        if (fgets(ibuf, siz, ifp) == 0 )  
  241.    242          {
  242.    243            if (verbose) printf("\nEOF after begin\n");
  243.    244            fclose(ofp);
  244.    245            
  245.    246            return;          
  246. +++ Warning: non-value return in non-void function
  247.    247          }
  248.    248        line++;
  249.    249        len = strlen(ibuf);
  250.    250        if (*ibuf == 'M')
  251.    251          {
  252.    252            if ((mlen = len) < 62)
  253.    253              {
  254.    254                if (verbose) printf("\ninvalid first data line %d\n", line);
  255.    255                fclose(ofp);
  256.    256                
  257.    257                continue;     
  258.    258              }
  259.    259            if (! secure)
  260.    260              ExplodeLine(ibuf);
  261.    261            else if (! ExplodeLineCheck(ibuf))
  262.    262              {
  263.    263                if (verbose) printf("\nillegal chars in first data line %d\n", line);
  264.    264                fclose(ofp);
  265.    265                
  266.    266                continue;     
  267.    267              }
  268.    268          }
  269.    269        else if (*ibuf <= 'L' && *ibuf > ' ')   
  270.    270          {
  271.    271            if (! secure)
  272.    272              ExplodeLine(ibuf);
  273.    273            else if (! ExplodeLineCheck(ibuf))
  274.    274              {
  275.    275                if (verbose) printf("\nillegal chars in short data line %d\n", line);
  276.    276                fclose(ofp);
  277.    277                continue;     
  278.    278              }
  279.    279  
  280.    280            
  281.    281            if (fgets(ibuf, siz, ifp) == 0 )
  282.    282              {
  283.    283                if (verbose) printf("\nwarning: EOF after short data line\n");
  284.    284                fclose(ofp);
  285.    285                return;         
  286. +++ Warning: non-value return in non-void function
  287.    286              }
  288.    287            len = strlen(ibuf);
  289.    288            
  290.    289            if (len != 2 && len != 3 || *ibuf != ' ' && *ibuf != '`')
  291.    290              {
  292.    291                if (verbose) printf("\nwarning: garbage at end %d\n", line+1);
  293.    292                
  294.    293                fseek(ifp, (long)-strlen(ibuf), 1);
  295.    294                fclose(ofp);
  296.    295              }
  297.    296            else
  298.    297              {
  299.    298                line++;
  300.    299                if (verbose) printf("-- done\n");
  301.    300                fclose(ofp);
  302.    301              }
  303.    302            continue;       
  304.    303          }
  305.    304        else if ((*ibuf == ' ' || *ibuf == '`') && (len == 2 || len == 3))
  306.    305          
  307.    306          {
  308.    307            if (verbose) printf("-- done\n");
  309.    308            fclose(ofp);
  310.    309            continue;       
  311.    310          }
  312.    311        else
  313.    312          {
  314.    313            if (verbose) printf("\ngarbage at first line %d\n", line);
  315.    314            fclose(ofp);
  316.    315            
  317.    316            continue;       
  318.    317          }
  319.    318        
  320.    319        
  321.    402  
  322.    402  
  323.    402  
  324.    402  
  325.    402  
  326.    402  
  327.    402  
  328.    402  
  329.    402  
  330.    402  
  331.    402  
  332.    402  
  333.    402  
  334.    402  
  335.    402  
  336.    402  
  337.    402  
  338.    402  
  339.    402  
  340.    402  
  341.    402  
  342.    402  
  343.    402  
  344.    402  
  345.    402  
  346.    402  
  347.    402  
  348.    402  
  349.    402  
  350.    402  
  351.    402  
  352.    402  
  353.    402  
  354.    402  
  355.    402  
  356.    402  
  357.    402  
  358.    402  
  359.    402  
  360.    402  
  361.    402  
  362.    402  
  363.    402  
  364.    402  
  365.    402  
  366.    402  
  367.    402  
  368.    402  
  369.    402  
  370.    402  
  371.    402  
  372.    402  
  373.    402  
  374.    402  
  375.    402  
  376.    402  
  377.    402  
  378.    402  
  379.    402  
  380.    402  
  381.    402  
  382.    402  
  383.    402  
  384.    402  
  385.    402  
  386.    402  
  387.    402  
  388.    402  
  389.    402  
  390.    402  
  391.    402  
  392.    402  
  393.    402  
  394.    402  
  395.    402  
  396.    402  
  397.    402  
  398.    402  
  399.    402  
  400.    402  
  401.    402  
  402.    402  
  403.    402  
  404.    403        
  405.    404        *bp = ' ';
  406.    405        
  407.    406        count = ambiguous = truncation = 0;
  408.    407        bquote = bquoteline = 0;
  409.    408        end = 0;
  410.    409        while (fgets(ibuf, siz, ifp) != 0 )
  411.    410          {
  412.    411            if ((newdata = ! strncmp(ibuf, "begin ", 6)
  413.    412                 && (__ctype[ibuf[6]] & 32 )
  414.    413                 && (__ctype[ibuf[7]] & 32 )
  415.    414                 && (__ctype[ibuf[8]] & 32 )) )     
  416.    416  
  417.    416              {        
  418.    417                fseek(ifp, (long)-strlen(ibuf), 1);
  419.    418                ExplodeLine(bp);
  420.    419                break;     
  421.    420              }
  422.    421            line++;
  423.    422            len = strlen(ibuf);
  424.    423            if (*ibuf <= 'L' && *ibuf > ' ')   
  425.    424              {
  426.    425                dlen = *ibuf-32;   
  427.    426                t = dlen/3;
  428.    427                if (dlen%3) t++;
  429.    428                t = t << 2;
  430.    429                if (len == t+2+(mlen-62))  
  431.    430                  if (uuchk(ibuf))     
  432.    431                    {
  433.    432                      tmp = bp;    
  434.    433                      bp = ibuf;
  435.    434                      ibuf = tmp;
  436.    435                      if (bquote)  
  437.    436                        {
  438.    437                          if (verbose) printf("\nwarning: bogus SPC-line %d  ", bquoteline);
  439.    438                          bquote = bquoteline = 0;
  440.    439                          
  441.    442  
  442.    442  
  443.    442                          truncation = 0;
  444.    443                        }
  445.    444                      ambiguous++; 
  446.    445                                   
  447.    446                      continue;    
  448.    447                    }
  449.    448                if (*bp != ' ') count++;
  450.    449                
  451.    453  
  452.    453  
  453.    453  
  454.    453                continue;
  455.    454              }
  456.    455            else if ((*ibuf == ' ' || *ibuf == '`' ) && (len == 2 || len == 3))
  457.    456              {
  458.    457                bquote = 1;         
  459.    458                if (bquoteline)     
  460.    459                  {
  461.    460                    if (verbose) printf("\nwarning: bogus SPC-line %d  ", bquoteline);
  462.    461                    truncation = 0;
  463.    462                  }
  464.    463                bquoteline = line;  
  465.    464                if (ambiguous)      
  466.    465                  {
  467.    466                    if (count > 0)
  468.    467                       if (verbose) printf("\nwarning: garbage at end %d  ", line);
  469.    468                    if (ambiguous > 1)
  470.    469                       if (verbose) printf("\nambiguous data at end %d  ", line);
  471.    470                    ExplodeLine(bp);
  472.    471                    break;            
  473.    472                  }
  474.    473              }
  475.    474            else if ((end = !strncmp(ibuf, "end\n", 4)) && ! ambiguous && bquote)
  476.    475              {
  477.    476                
  478.    477                break;      
  479.    478              }
  480.    479            else if (*ibuf == 'M')     
  481.    480              {
  482.    481                if (len != mlen)
  483.    482                  {
  484.    483                    if (verbose && uuchk(ibuf))   
  485.    484                      {
  486.    485                        if (! truncation)
  487.    486                          {
  488.    487                            printf("\nwarning: truncated data line %d ", line);
  489.    488                            fflush((&__iob[1]));
  490.    489                            truncation = 1;
  491.    490                          }
  492.    491                        else
  493.    492                          {
  494.    493                            printf("%d ", line);
  495.    494                            fflush((&__iob[1]));
  496.    495                          }
  497.    496                      }
  498.    497                  }
  499.    498                else
  500.    499                  {
  501.    500                    mode = 1;     
  502.    501                    if (! secure)
  503.    502                      ExplodeLine(ibuf);
  504.    503                    else
  505.    504                    {
  506.    505                       mode = ExplodeLineCheck(ibuf);
  507.    506                       ;
  508.    507                    }
  509.    508                    if (mode)
  510.    509                    {
  511.    510                      
  512.    511                      count = ambiguous = 0;
  513.    512                      if (bquote)       
  514.    513                      {
  515.    514                         if (verbose) printf("\nwarning: bogus SPC-line %d  ", bquoteline);
  516.    515                         bquoteline = bquote = 0;
  517.    516                         
  518.    520  
  519.    520  
  520.    520  
  521.    520                         truncation = 0;
  522.    521                      }
  523.    522                    }
  524.    523                 }
  525.    524              }
  526.    525          } 
  527.    526        fclose(ofp);
  528.    527        
  529.    528        if (! ambiguous && ! end) if (verbose) printf("\nwarning: no end line  ");
  530.    529        if (! bquote)
  531.    530          {if (verbose) printf("\nend of uucode not found\n");}
  532.    531        else
  533.    532          {if (verbose) printf("-- done\n");}
  534.    533      } 
  535.    534  }
  536. +++ Warning: implicit return in non-void function
  537.    535  
  538.    536  
  539.    537  
  540.    548  
  541.    548  
  542.    548  
  543.    548  
  544.    548  
  545.    548  
  546.    548  
  547.    548  
  548.    548  
  549.    548  
  550.    548  
  551.    549  
  552.    550  ExplodeLine(char *str)
  553.    551  {
  554.    552    i = (((*str) - ' ') & 077);    
  555.    553    p = ++str;
  556.    554    
  557.    555    while (i > 0)
  558.    556      {
  559.    557        if (i >= 3)
  560.    558          {
  561.    559            x  = ((((*p) - ' ') & 077) << 2); p++;
  562.    560            x |= ((((*p) - ' ') & 077) >> 4);
  563.    561            y  = ((((*p) - ' ') & 077) << 4); p++;
  564.    562            y |= ((((*p) - ' ') & 077) >> 2);
  565.    563            z  = ((((*p) - ' ') & 077) << 6); p++;
  566.    564            z |= ((((*p) - ' ') & 077));
  567.    565            (--((ofp)->__ocnt) >= 0 ? (*((ofp)->__ptr)++ = (x)) : __flsbuf(x,ofp));
  568.    566            (--((ofp)->__ocnt) >= 0 ? (*((ofp)->__ptr)++ = (y)) : __flsbuf(y,ofp));
  569.    567            (--((ofp)->__ocnt) >= 0 ? (*((ofp)->__ptr)++ = (z)) : __flsbuf(z,ofp));
  570.    568          }
  571.    569        else if (i >= 2)
  572.    570          {
  573.    571            x  = ((((*p) - ' ') & 077) << 2); p++;
  574.    572            x |= ((((*p) - ' ') & 077) >> 4);
  575.    573            y  = ((((*p) - ' ') & 077) << 4); p++;
  576.    574            y |= ((((*p) - ' ') & 077) >> 2);
  577.    575            (--((ofp)->__ocnt) >= 0 ? (*((ofp)->__ptr)++ = (x)) : __flsbuf(x,ofp));
  578.    576            (--((ofp)->__ocnt) >= 0 ? (*((ofp)->__ptr)++ = (y)) : __flsbuf(y,ofp));
  579.    577          }
  580.    578        else if (i >= 1)
  581.    579          {
  582.    580            x  = ((((*p) - ' ') & 077) << 2); p++;
  583.    581            x |= ((((*p) - ' ') & 077) >> 4);
  584.    582            (--((ofp)->__ocnt) >= 0 ? (*((ofp)->__ptr)++ = (x)) : __flsbuf(x,ofp));
  585.    583          }
  586.    584        
  587.    585        str += 4;
  588.    586        p = str;
  589.    587        i -= 3;
  590.    588      }  
  591.    589  }
  592.    590  
  593.    591  
  594.    592  
  595.    596  
  596.    596  
  597.    596  
  598.    596  unsigned char data[50];
  599.    597  
  600.    598  
  601.    603  
  602.    603  
  603.    603  
  604.    603  
  605.    603  int ExplodeLineCheck(char *str)
  606.    604  {
  607.    605    unsigned char *d;
  608.    606  
  609.    607    i = (((*str) - ' ') & 077);    
  610.    608    p = ++str;
  611.    609    d = data;
  612.    610    while (i > 0)
  613.    611      {
  614.    612        if (i >= 3)
  615.    613          {
  616.    614            x  = ((((*p) - ' ') & 077) << 2); p++;
  617.    615            x |= ((((*p) - ' ') & 077) >> 4);
  618.    616            y  = ((((*p) - ' ') & 077) << 4); p++;
  619.    617            y |= ((((*p) - ' ') & 077) >> 2);
  620.    618            z  = ((((*p) - ' ') & 077) << 6); p++;
  621.    619            z |= ((((*p) - ' ') & 077));
  622.    620            *d++ = x; *d++ = y; *d++ = z;
  623.    621            
  624.    622            if (*p >= 'a' || *(p-1) >= 'a' || *(p-2) >= 'a' || *(p-3) >= 'a')
  625.    623              return(0);
  626.    624          }
  627.    625        else if (i >= 2)
  628.    626          {
  629.    627            x  = ((((*p) - ' ') & 077) << 2); p++;
  630.    628            x |= ((((*p) - ' ') & 077) >> 4);
  631.    629            y  = ((((*p) - ' ') & 077) << 4); p++;
  632.    630            y |= ((((*p) - ' ') & 077) >> 2);
  633.    631            *d++ = x; *d++ = y;
  634.    632            
  635.    633            if (*p >= 'a' || *(p-1) >= 'a' || *(p-2) >= 'a')
  636.    634              return(0);
  637.    635          }
  638.    636        else if (i >= 1)
  639.    637          {
  640.    638            x  = ((((*p) - ' ') & 077) << 2); p++;
  641.    639            x |= ((((*p) - ' ') & 077) >> 4);
  642.    640            *d++ = x;
  643.    641            if (*p >= 'a' || *(p-1) >= 'a')
  644.    642              return(0);
  645.    643          }
  646.    644        str += 4;
  647.    645        p = str;
  648.    646        i -= 3;
  649.    647      }  
  650.    648      *d = 0;   
  651.    649      fwrite(data, 1, d-data, ofp);
  652.    650      return(1);
  653.    651  }
  654.    652  
  655.    653  
  656. +++ Warning: static 'obuf' declared but not used
  657.